package com.hyk.commonLib.common.utils;

import android.app.Activity;
import android.content.Context;
import android.view.ContextThemeWrapper;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * Created by 贺玉琨 on 2021/1/13.
 */
public class ViewUtils {
    @Nullable
    public static Activity getActivity(@Nullable View v) {
        if (v == null) return null;
        Context context = v.getContext();
        if (context instanceof Activity) {
            return (Activity) context;
        } else if (context instanceof ContextThemeWrapper && ((ContextThemeWrapper) context).getBaseContext() instanceof Activity) {
            return (Activity) ((ContextThemeWrapper) context).getBaseContext();
        }
        return null;
    }
}
